/**
* @description: 260. 只出现一次的数字 III
* @author hewei
* @date 2022/7/29 16:33
* @version 1.0
*/

public class SingleNumber3 {

    public int[] singleNumber(int[] nums) {
        int temp = nums[0];
        for (int i = 1; i < nums.length; i++) {
            temp ^= nums[i];
        }
        int oneBit = Integer.lowestOneBit(temp);
        int a = 0;
        int b = 0;
        for (int num : nums) {
            if ((num & oneBit) == 0) {
                a ^= num;
            } else b ^= num;
        }
        return new int[]{a, b};
    }
}
